package cn.gok.util;

import java.util.HashMap;
//自定义的一个相应结果集,用来响应给前端的数据
public class R<T> extends HashMap {
    private String msg;
    //状态码
    private int code;
    //响应数据
    private T data;
    //键名
    public static final String CODE="code";
    public static final String MSG="msg";
    public static final String DATA="data";


    public R() {
    }

    public R(String msg, int code, T data) {
        super.put("msg",msg);
        super.put("code",code);
        super.put("data",data);

    }
    /*
    *
     */
    public static R success(String msg){
        return new R(msg,Const.SUCCESS_CODE,null);
    }
    public static R success1(String msg){
        return new R(msg,Const.SUCCESS_CODE1,null);
    }
    public static R fail(String msg){
        return new R(msg,Const.FAIL_CODE,null);
    }
    public static R success(){
        return new R(Const.SUCCESS_OPERATION_MSG,Const.SUCCESS_CODE,null);
    }
    public static R success1(){
        return new R(Const.LOGIN_SUCCESS_MSG,Const.SUCCESS_CODE1,null);
    }
    public static R fail(){
        return new R(Const.FAIL_OPERATION_MSG,Const.FAIL_CODE,null);
    }
    public static R create(Object data){
        return new R(null,Const.SUCCESS_CODE,data);
    }
    public static R fail(int code,String msg){
        return new R(msg,code,null);
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    @Override
    public String toString() {
        return "R{" +
                "msg='" + msg + '\'' +
                ", code=" + code +
                ", data=" + data +
                '}';
    }
}
